The three ideas that make code actually powerful — watch them all today
Day 6 of 40 — Week 2 begins
if/elif/else lets code make decisionsfor and while loops automate repetitionThis is a longer session — block out 60–90 minutes with Cursor open next to the video. You're watching the second half of Mosh's course, which covers three connected ideas back-to-back.
Watch from the 1-hour mark through to the end
Have Cursor open next to the video. Every time Mosh types something, you type it too. When he writes an if condition, try changing the condition yourself before he moves on. Pause often. Going slower today means you go faster all week.
The most fundamental idea in programming: if something is true, do this. Otherwise, do that.
if, elif, else — the branching structure==, !=, <, >, <=, >=and, or, notOne of the most common beginner mistakes: = assigns a value. == checks equality. platform = "Kling" stores the value. platform == "Kling" asks a question. You will mix these up. When you do, come back here.
A for loop runs a block of code once for each item in a list. A while loop runs until a condition stops being true.
for item in list: — process each item in a collectionfor i in range(n): — repeat n timeswhile condition: — keep going until something changesbreak — exit the loop earlyA list holds multiple items in one variable. This is the data structure you'll use more than any other.
shots = ["wide", "medium", "close-up"].append(), .remove(), .sort()len() — count items in a listPython evaluates conditions as True or False. But almost everything in Python has a truth value — you can use any value in an if statement, not just booleans.
These count as False: empty string "", zero 0, empty list [], and None.
Everything else — non-empty strings, non-zero numbers, lists with items — counts as True.
This sounds abstract now. Tomorrow you'll test it in Jupyter and it'll click. For now, just know it exists.
These patterns appear constantly in real Python. Watch for them today so they start feeling familiar:
| Pattern | What it does |
|---|---|
if x == "value": |
Check if a variable holds a specific value |
for item in list: |
Loop through every item in a list |
for i in range(5): |
Loop exactly 5 times (i = 0, 1, 2, 3, 4) |
while True: ... break |
Run forever until you explicitly break out |
list.append(item) |
Add an item to the end of a list |
if item in list: |
Check if an item exists in a list |
Today was exposure, not mastery. You saw a lot of new syntax in one session. Tomorrow you'll slow down, experiment in Jupyter one concept at a time, and the pieces will start connecting. The goal of today was to see the whole picture. Tomorrow you zoom in.